


import java.util.LinkedList;
import java.util.List;

import javax.swing.JOptionPane;


public class OrderedCascade {
	private List<Card> ocascade;
	
	public OrderedCascade(){
		ocascade = new LinkedList<Card>();
	}
	public boolean add(Card c){
		if(ocascade.size() == 0){
			ocascade.add(c);
			return true;
		}
		if((ocascade.get(ocascade.size()-1).getSuite() % 2 != c.getSuite() %2) && 
			(ocascade.get(ocascade.size()-1).getValue()-1 == c.getValue())){
			ocascade.add(c);
			return true;
		}
		return false;
	}
	public OrderedCascade remove(int i){
		OrderedCascade temp = new OrderedCascade();
		if(i>=0 && i<ocascade.size()){
			for(int j = 0; j < i; j++)
				temp.add(ocascade.remove(ocascade.size()-i));
			return temp;
		}
		return null;
	}
	public Card removeTop(){
		return ocascade.remove(ocascade.size()-1);
	}
	public Card removeBottom(){
		return ocascade.remove(0);
	}
	public Card getTop(){
		if(ocascade.size()-1 < 0)
			return null;
		return ocascade.get(ocascade.size()-1);
	}
	public Card getBottom(){
		return ocascade.get(0);
	}
	public Card get(int index){
		return ocascade.get(index);
	}
	public OrderedCascade getOrderedCascade(){
		//To avoid passing direct ref
		OrderedCascade temp = new OrderedCascade();
		for(Card c: ocascade)
			temp.add(c);
		return temp;
	}
	public int size(){
		return ocascade.size();
	}
	public void consolidate(OrderedCascade oc){
		int k = oc.size();
		for(int i=0; i<k; i++)
			this.add(oc.removeBottom());
	}
	public Card getOrderedCascadeCards(int i){
		return ocascade.get(i);
	}
}